package com.xsd.awen.utils;

import org.springframework.beans.BeanUtils;

import java.lang.reflect.Field;
import java.util.List;

public class ClassUtils {

    public static List<String> getProperties(Class<?> clazz){
        Field[] fields = clazz.getDeclaredFields();
        List<String> properties = Lists.newArrayList();

        for( Field field : fields ){
            System.out.println(field.getName());
            properties.add(field.getName());
        }

        return properties;
    }

    public static <T> T cloneEntity(Class<T> clazz, T entity){
        T result = null;
        try {
            result = clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        BeanUtils.copyProperties(entity,result);

        return result;
    }


}
